﻿Imports MySql.Data.MySqlClient
Imports System.IO
Imports System.Data

Public Class Edit2
    Dim sql As MySqlConnection
    Dim idkey As String
    Dim ipconnect As String
    Dim usernamedb As String
    Dim dbname As String
    Dim mysqlpass As String

    Public Sub New(ByRef mysql_pass As String, ByRef ip_connect As String, ByRef user_namedb As String, ByRef db_name As String)
        InitializeComponent()
        mysqlpass = mysql_pass
        ipconnect = ip_connect
        usernamedb = user_namedb
        dbname = db_name
    End Sub

    Private Sub Edit2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        sql = New MySqlConnection
        sql.ConnectionString = "server=" + ipconnect + ";user id=" + usernamedb + ";password=" + mysqlpass + ";database=" + dbname + ";Character Set =utf8;"
        Try
            sql.Open()
            ' MsgBox("CONNECTED TO DATABASE")
        Catch ex As Exception
            MsgBox("Can't Connect to database" + ex.Message)
            Me.Close()
        End Try
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader


        ''เริ่มต้นโค้ด


        mySqlCommand.CommandText = "SELECT * FROM data_device where type = 'Computer' order by iddata_device;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand
        Try
            mySqlReader = mySqlCommand.ExecuteReader

            ListViewcom.Items.Clear()

            While (mySqlReader.Read())

                With ListViewcom.Items.Add(mySqlReader("iddata_device"))
                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Computer")
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Printer")
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Monitor")
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Other")
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.add("Licens")
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.add("Network")
                    End If
                    .SubItems.Add(mySqlReader("name"))

                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "CPU : " + mySqlReader("c_cpu") + "mainboard : " + mySqlReader("c_mainboard") + "RAM : " + mySqlReader("c_ram") + "HARDDISK : " + mySqlReader("c_harddisk") + "VGA Card : " + mySqlReader("c_vgacard") + "Ip Number : " + mySqlReader("c_ipnumber") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "PowerSupply : " + mySqlReader("c_ps") + "CD/DVD : " + mySqlReader("c_cd") + "Case : " + mySqlReader("c_case") + "IpAddress : " + mySqlReader("c_ipnumber") + "Computername : " + mySqlReader("c_comname") + " Windows : " + mySqlReader("c_windows") + "Office : " + mySqlReader("c_office") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Size : " + mySqlReader("m_size") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Type : " + mySqlReader("p_type") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.Add("Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price") + "Amount : " + mySqlReader("amount"))
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.Add("Serial Number : " + mySqlReader("serialnumber") + "IP Address : " + mySqlReader("c_ipnumber") + "Pass-Connect : " + mySqlReader("pass_connect") + "Pass-Config : " + mySqlReader("pass_config") + "Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("state_device") IsNot DBNull.Value Then
                        .SubItems.Add(mySqlReader("state_device"))
                    End If
                End With
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()


        ''เริ่มต้นหน้าใหม่ TYPE "P"


        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        mySqlCommand.CommandText = "SELECT * FROM data_device where type = 'Printer' order by iddata_device;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand
        Try
            mySqlReader = mySqlCommand.ExecuteReader

            ListViewprin.Items.Clear()

            While (mySqlReader.Read())

                With ListViewprin.Items.Add(mySqlReader("iddata_device"))
                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Computer")
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Printer")
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Monitor")
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Other")
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.add("Licens")
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.add("Network")
                    End If
                    .SubItems.Add(mySqlReader("name"))

                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "CPU : " + mySqlReader("c_cpu") + "mainboard : " + mySqlReader("c_mainboard") + "RAM : " + mySqlReader("c_ram") + "HARDDISK : " + mySqlReader("c_harddisk") + "VGA Card : " + mySqlReader("c_vgacard") + "Ip Number : " + mySqlReader("c_ipnumber") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "PowerSupply : " + mySqlReader("c_ps") + "CD/DVD : " + mySqlReader("c_cd") + "Case : " + mySqlReader("c_case") + "IpAddress : " + mySqlReader("c_ipnumber") + "Computername : " + mySqlReader("c_comname") + " Windows : " + mySqlReader("c_windows") + "Office : " + mySqlReader("c_office") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Size : " + mySqlReader("m_size") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Type : " + mySqlReader("p_type") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.Add("Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price") + "Amount : " + mySqlReader("amount"))
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.Add("Serial Number : " + mySqlReader("serialnumber") + "IP Address : " + mySqlReader("c_ipnumber") + "Pass-Connect : " + mySqlReader("pass_connect") + "Pass-Config : " + mySqlReader("pass_config") + "Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("state_device") IsNot DBNull.Value Then
                        .SubItems.Add(mySqlReader("state_device"))
                    End If

                End With
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()


        ''เริ่มต้นหน้าใหม่ TYPE "M"


        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        mySqlCommand.CommandText = "SELECT * FROM data_device where type = 'Monitor' order by iddata_device;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand
        Try
            mySqlReader = mySqlCommand.ExecuteReader

            ListViewmonitor.Items.Clear()

            While (mySqlReader.Read())

                With ListViewmonitor.Items.Add(mySqlReader("iddata_device"))
                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Computer")
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Printer")
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Monitor")
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Other")
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.add("Licens")
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.add("Network")
                    End If
                    .SubItems.Add(mySqlReader("name"))


                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "CPU : " + mySqlReader("c_cpu") + "mainboard : " + mySqlReader("c_mainboard") + "RAM : " + mySqlReader("c_ram") + "HARDDISK : " + mySqlReader("c_harddisk") + "VGA Card : " + mySqlReader("c_vgacard") + "Ip Number : " + mySqlReader("c_ipnumber") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "PowerSupply : " + mySqlReader("c_ps") + "CD/DVD : " + mySqlReader("c_cd") + "Case : " + mySqlReader("c_case") + "IpAddress : " + mySqlReader("c_ipnumber") + "Computername : " + mySqlReader("c_comname") + " Windows : " + mySqlReader("c_windows") + "Office : " + mySqlReader("c_office") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Size : " + mySqlReader("m_size") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Type : " + mySqlReader("p_type") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.Add("Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price") + "Amount : " + mySqlReader("amount"))
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.Add("Serial Number : " + mySqlReader("serialnumber") + "IP Address : " + mySqlReader("c_ipnumber") + "Pass-Connect : " + mySqlReader("pass_connect") + "Pass-Config : " + mySqlReader("pass_config") + "Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("state_device") IsNot DBNull.Value Then
                        .SubItems.Add(mySqlReader("state_device"))
                    End If
                End With
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()


        ''เริ่มต้นหน้าใหม่ TYPE "O"


        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        mySqlCommand.CommandText = "SELECT * FROM data_device where type = 'Other' order by iddata_device;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand
        Try
            mySqlReader = mySqlCommand.ExecuteReader

            ListViewother.Items.Clear()

            While (mySqlReader.Read())

                With ListViewother.Items.Add(mySqlReader("iddata_device"))
                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Computer")
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Printer")
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Monitor")
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Other")
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.add("Licens")
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.add("Network")
                    End If
                    .SubItems.Add(mySqlReader("name"))


                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "CPU : " + mySqlReader("c_cpu") + "mainboard : " + mySqlReader("c_mainboard") + "RAM : " + mySqlReader("c_ram") + "HARDDISK : " + mySqlReader("c_harddisk") + "VGA Card : " + mySqlReader("c_vgacard") + "Ip Number : " + mySqlReader("c_ipnumber") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "PowerSupply : " + mySqlReader("c_ps") + "CD/DVD : " + mySqlReader("c_cd") + "Case : " + mySqlReader("c_case") + "IpAddress : " + mySqlReader("c_ipnumber") + "Computername : " + mySqlReader("c_comname") + " Windows : " + mySqlReader("c_windows") + "Office : " + mySqlReader("c_office") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Size : " + mySqlReader("m_size") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Type : " + mySqlReader("p_type") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.Add("Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price") + "Amount : " + mySqlReader("amount"))
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.Add("Serial Number : " + mySqlReader("serialnumber") + "IP Address : " + mySqlReader("c_ipnumber") + "Pass-Connect : " + mySqlReader("pass_connect") + "Pass-Config : " + mySqlReader("pass_config") + "Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("state_device") IsNot DBNull.Value Then
                        .SubItems.Add(mySqlReader("state_device"))
                    End If
                End With
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()


        ''เริ่มต้นหน้าใหม่ TYPE "L"


        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        mySqlCommand.CommandText = "SELECT * FROM data_device where type = 'License' order by iddata_device;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand
        Try
            mySqlReader = mySqlCommand.ExecuteReader

            ListViewlicense.Items.Clear()

            While (mySqlReader.Read())

                With ListViewlicense.Items.Add(mySqlReader("iddata_device"))
                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Computer")
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Printer")
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Monitor")
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Other")
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.add("Licens")
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.add("Network")
                    End If
                    .SubItems.Add(mySqlReader("name"))


                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "CPU : " + mySqlReader("c_cpu") + "mainboard : " + mySqlReader("c_mainboard") + "RAM : " + mySqlReader("c_ram") + "HARDDISK : " + mySqlReader("c_harddisk") + "VGA Card : " + mySqlReader("c_vgacard") + "Ip Number : " + mySqlReader("c_ipnumber") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "PowerSupply : " + mySqlReader("c_ps") + "CD/DVD : " + mySqlReader("c_cd") + "Case : " + mySqlReader("c_case") + "IpAddress : " + mySqlReader("c_ipnumber") + "Computername : " + mySqlReader("c_comname") + " Windows : " + mySqlReader("c_windows") + "Office : " + mySqlReader("c_office") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Size : " + mySqlReader("m_size") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Type : " + mySqlReader("p_type") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.Add("Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price") + "Amount : " + mySqlReader("amount"))
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.Add("Serial Number : " + mySqlReader("serialnumber") + "IP Address : " + mySqlReader("c_ipnumber") + "Pass-Connect : " + mySqlReader("pass_connect") + "Pass-Config : " + mySqlReader("pass_config") + "Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("state_device") IsNot DBNull.Value Then
                        .SubItems.Add(mySqlReader("state_device"))
                    End If
                End With
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()


        ''เริ่มต้นหน้าใหม่ TYPE "N"


        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        mySqlCommand.CommandText = "SELECT * FROM data_device where type = 'Network' order by iddata_device;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand
        Try
            mySqlReader = mySqlCommand.ExecuteReader

            ListViewnet.Items.Clear()

            While (mySqlReader.Read())

                With ListViewnet.Items.Add(mySqlReader("iddata_device"))
                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Computer")
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Printer")
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Monitor")
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Other")
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.add("Licens")
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.add("Network")
                    End If
                    .SubItems.Add(mySqlReader("name"))

                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "CPU : " + mySqlReader("c_cpu") + "mainboard : " + mySqlReader("c_mainboard") + "RAM : " + mySqlReader("c_ram") + "HARDDISK : " + mySqlReader("c_harddisk") + "VGA Card : " + mySqlReader("c_vgacard") + "Ip Number : " + mySqlReader("c_ipnumber") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "PowerSupply : " + mySqlReader("c_ps") + "CD/DVD : " + mySqlReader("c_cd") + "Case : " + mySqlReader("c_case") + "IpAddress : " + mySqlReader("c_ipnumber") + "Computername : " + mySqlReader("c_comname") + " Windows : " + mySqlReader("c_windows") + "Office : " + mySqlReader("c_office") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Size : " + mySqlReader("m_size") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Type : " + mySqlReader("p_type") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.Add("Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price") + "Amount : " + mySqlReader("amount"))
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.Add("Serial Number : " + mySqlReader("serialnumber") + "IP Address : " + mySqlReader("c_ipnumber") + "Pass-Connect : " + mySqlReader("pass_connect") + "Pass-Config : " + mySqlReader("pass_config") + "Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("state_device") IsNot DBNull.Value Then
                        .SubItems.Add(mySqlReader("state_device"))
                    End If
                End With
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()
    End Sub

    '' โค้ด โชว์ข้อมูลในตารางสัมพันธ์กับปุ่ม search

    ''computer
    Private Sub showdatacom1()
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim key As String
        Dim count As Integer

        count = 0
        key = txtsearchcom.Text

        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If

        mySqlCommand.CommandText = "SELECT * FROM data_device where  type = 'Computer' and ( name like '%" + key + "%'  or  model like '%" + key + "%'   or  c_cpu like '%" + key + "%'  or  c_mainboard like '%" + key + "%' or  c_ram like '%" + key + "%' or  c_harddisk like '%" + key + "%' or  c_vgacard like '%" + key + "%'  or  state_device like '%" + key + "%' or  p_type like '%" + key + "%'or  m_size like '%" + key + "%' or  detail like '%" + key + "%'or  c_ipnumber like '%" + key + "%' or  c_ps like '%" + key + "%' or  c_cd like '%" + key + "%' or  c_case like '%" + key + "%' or  serialnumber like '%" + key + "%' or  c_comname like '%" + key + "%'or  c_windows like '%" + key + "%'or  c_office like '%" + key + "%'or  c_other like '%" + key + "%')  order by iddata_device;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            ListViewcom.Items.Clear()

            While (mySqlReader.Read())

                With ListViewcom.Items.Add(mySqlReader("iddata_device"))
                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Computer")
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Printer")
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Monitor")
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Other")
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.add("Licens")
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.add("Network")
                    End If
                    .SubItems.Add(mySqlReader("name"))


                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "CPU : " + mySqlReader("c_cpu") + "mainboard : " + mySqlReader("c_mainboard") + "RAM : " + mySqlReader("c_ram") + "HARDDISK : " + mySqlReader("c_harddisk") + "VGA Card : " + mySqlReader("c_vgacard") + "Ip Number : " + mySqlReader("c_ipnumber") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "PowerSupply : " + mySqlReader("c_ps") + "CD/DVD : " + mySqlReader("c_cd") + "Case : " + mySqlReader("c_case") + "IpAddress : " + mySqlReader("c_ipnumber") + "Computername : " + mySqlReader("c_comname") + " Windows : " + mySqlReader("c_windows") + "Office : " + mySqlReader("c_office") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Size : " + mySqlReader("m_size") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Type : " + mySqlReader("p_type") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.Add("Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price") + "Amount : " + mySqlReader("amount"))
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.Add("Serial Number : " + mySqlReader("serialnumber") + "IP Address : " + mySqlReader("c_ipnumber") + "Pass-Connect : " + mySqlReader("pass_connect") + "Pass-Config : " + mySqlReader("pass_config") + "Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("state_device") IsNot DBNull.Value Then
                        .SubItems.Add(mySqlReader("state_device"))
                    End If

                End With
            End While

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()
    End Sub

    ''printer
    Private Sub showdataprinter2()
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim key As String
        Dim count As Integer

        count = 0
        key = txtsearchprin.Text

        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If



        mySqlCommand.CommandText = "SELECT * FROM data_device where  type = 'Printer' and ( name like '%" + key + "%'  or  model like '%" + key + "%'    or  serialnumber like '%" + key + "%'  or  detail like '%" + key + "%' )  order by iddata_device;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader
            ListViewprin.Items.Clear()

            While (mySqlReader.Read())

                With ListViewprin.Items.Add(mySqlReader("iddata_device"))
                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Computer")
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Printer")
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Monitor")
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Other")
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.add("Licens")
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.add("Network")
                    End If
                    .SubItems.Add(mySqlReader("name"))


                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "CPU : " + mySqlReader("c_cpu") + "mainboard : " + mySqlReader("c_mainboard") + "RAM : " + mySqlReader("c_ram") + "HARDDISK : " + mySqlReader("c_harddisk") + "VGA Card : " + mySqlReader("c_vgacard") + "Ip Number : " + mySqlReader("c_ipnumber") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "PowerSupply : " + mySqlReader("c_ps") + "CD/DVD : " + mySqlReader("c_cd") + "Case : " + mySqlReader("c_case") + "IpAddress : " + mySqlReader("c_ipnumber") + "Computername : " + mySqlReader("c_comname") + " Windows : " + mySqlReader("c_windows") + "Office : " + mySqlReader("c_office") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Size : " + mySqlReader("m_size") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Type : " + mySqlReader("p_type") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.Add("Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price") + "Amount : " + mySqlReader("amount"))
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.Add("Serial Number : " + mySqlReader("serialnumber") + "IP Address : " + mySqlReader("c_ipnumber") + "Pass-Connect : " + mySqlReader("pass_connect") + "Pass-Config : " + mySqlReader("pass_config") + "Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("state_device") IsNot DBNull.Value Then
                        .SubItems.Add(mySqlReader("state_device"))
                    End If

                End With
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()
    End Sub

    ''monitor
    Private Sub showdatamonitor3()
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim key As String
        Dim count As Integer

        count = 0
        key = txtsearchmonitor.Text

        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If

        mySqlCommand.CommandText = "SELECT * FROM data_device where  type = 'Monitor' and ( name like '%" + key + "%'  or  model like '%" + key + "%'    or  m_size like '%" + key + "%'  or  serialnumber like '%" + key + "%'  or  detail like '%" + key + "%')  order by iddata_device;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            ListViewmonitor.Items.Clear()

            While (mySqlReader.Read())

                With ListViewmonitor.Items.Add(mySqlReader("iddata_device"))
                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Computer")
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Printer")
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Monitor")
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Other")
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.add("Licens")
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.add("Network")
                    End If
                    .SubItems.Add(mySqlReader("name"))


                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "CPU : " + mySqlReader("c_cpu") + "mainboard : " + mySqlReader("c_mainboard") + "RAM : " + mySqlReader("c_ram") + "HARDDISK : " + mySqlReader("c_harddisk") + "VGA Card : " + mySqlReader("c_vgacard") + "Ip Number : " + mySqlReader("c_ipnumber") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "PowerSupply : " + mySqlReader("c_ps") + "CD/DVD : " + mySqlReader("c_cd") + "Case : " + mySqlReader("c_case") + "IpAddress : " + mySqlReader("c_ipnumber") + "Computername : " + mySqlReader("c_comname") + " Windows : " + mySqlReader("c_windows") + "Office : " + mySqlReader("c_office") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Size : " + mySqlReader("m_size") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Type : " + mySqlReader("p_type") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.Add("Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price") + "Amount : " + mySqlReader("amount"))
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.Add("Serial Number : " + mySqlReader("serialnumber") + "IP Address : " + mySqlReader("c_ipnumber") + "Pass-Connect : " + mySqlReader("pass_connect") + "Pass-Config : " + mySqlReader("pass_config") + "Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("state_device") IsNot DBNull.Value Then
                        .SubItems.Add(mySqlReader("state_device"))
                    End If

                End With
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()
    End Sub

    ''other
    Private Sub showdataother4()
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim key As String
        Dim count As Integer

        count = 0
        key = txtsearchother.Text

        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If

        mySqlCommand.CommandText = "SELECT * FROM data_device where  type = 'Other' and ( name like '%" + key + "%'  or  model like '%" + key + "%'  or  serialnumber like '%" + key + "%'   or  detail like '%" + key + "%')  order by iddata_device;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            ListViewother.Items.Clear()

            While (mySqlReader.Read())

                With ListViewother.Items.Add(mySqlReader("iddata_device"))
                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Computer")
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Printer")
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Monitor")
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Other")
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.add("Licens")
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.add("Network")
                    End If
                    .SubItems.Add(mySqlReader("name"))

                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "CPU : " + mySqlReader("c_cpu") + "mainboard : " + mySqlReader("c_mainboard") + "RAM : " + mySqlReader("c_ram") + "HARDDISK : " + mySqlReader("c_harddisk") + "VGA Card : " + mySqlReader("c_vgacard") + "Ip Number : " + mySqlReader("c_ipnumber") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "PowerSupply : " + mySqlReader("c_ps") + "CD/DVD : " + mySqlReader("c_cd") + "Case : " + mySqlReader("c_case") + "IpAddress : " + mySqlReader("c_ipnumber") + "Computername : " + mySqlReader("c_comname") + " Windows : " + mySqlReader("c_windows") + "Office : " + mySqlReader("c_office") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Size : " + mySqlReader("m_size") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Type : " + mySqlReader("p_type") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.Add("Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price") + "Amount : " + mySqlReader("amount"))
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.Add("Serial Number : " + mySqlReader("serialnumber") + "IP Address : " + mySqlReader("c_ipnumber") + "Pass-Connect : " + mySqlReader("pass_connect") + "Pass-Config : " + mySqlReader("pass_config") + "Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("state_device") IsNot DBNull.Value Then
                        .SubItems.Add(mySqlReader("state_device"))
                    End If

                End With
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()
    End Sub

    ''license
    Private Sub showdatalicense5()
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim key As String
        Dim count As Integer

        count = 0
        key = txtsearchother.Text

        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If

        mySqlCommand.CommandText = "SELECT * FROM data_device where  type = 'License' and ( name like '%" + key + "%'  or  model like '%" + key + "%'  or  serialnumber like '%" + key + "%'   or  detail like '%" + key + "%')  order by iddata_device;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            ListViewlicense.Items.Clear()

            While (mySqlReader.Read())

                With ListViewlicense.Items.Add(mySqlReader("iddata_device"))
                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Computer")
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Printer")
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Monitor")
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Other")
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.add("Licens")
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.add("Network")
                    End If
                    .SubItems.Add(mySqlReader("name"))


                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "CPU : " + mySqlReader("c_cpu") + "mainboard : " + mySqlReader("c_mainboard") + "RAM : " + mySqlReader("c_ram") + "HARDDISK : " + mySqlReader("c_harddisk") + "VGA Card : " + mySqlReader("c_vgacard") + "Ip Number : " + mySqlReader("c_ipnumber") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "PowerSupply : " + mySqlReader("c_ps") + "CD/DVD : " + mySqlReader("c_cd") + "Case : " + mySqlReader("c_case") + "IpAddress : " + mySqlReader("c_ipnumber") + "Computername : " + mySqlReader("c_comname") + " Windows : " + mySqlReader("c_windows") + "Office : " + mySqlReader("c_office") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Size : " + mySqlReader("m_size") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Type : " + mySqlReader("p_type") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.Add("Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price") + "Amount : " + mySqlReader("amount"))
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.Add("Serial Number : " + mySqlReader("serialnumber") + "IP Address : " + mySqlReader("c_ipnumber") + "Pass-Connect : " + mySqlReader("pass_connect") + "Pass-Config : " + mySqlReader("pass_config") + "Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("state_device") IsNot DBNull.Value Then
                        .SubItems.Add(mySqlReader("state_device"))
                    End If

                End With
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()
    End Sub

    ''Network
    Private Sub showdatanetwork6()
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim key As String
        Dim count As Integer

        count = 0
        key = txtsearchother.Text

        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If

        mySqlCommand.CommandText = "SELECT * FROM data_device where  type = 'Network' and ( name like '%" + key + "%'  or  model like '%" + key + "%'  or  serialnumber like '%" + key + "%'   or  detail like '%" + key + "%')  order by iddata_device;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            ListViewnet.Items.Clear()

            While (mySqlReader.Read())

                With ListViewnet.Items.Add(mySqlReader("iddata_device"))
                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Computer")
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Printer")
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Monitor")
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Other")
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.add("Licens")
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.add("Network")
                    End If
                    .SubItems.Add(mySqlReader("name"))

                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "CPU : " + mySqlReader("c_cpu") + "mainboard : " + mySqlReader("c_mainboard") + "RAM : " + mySqlReader("c_ram") + "HARDDISK : " + mySqlReader("c_harddisk") + "VGA Card : " + mySqlReader("c_vgacard") + "Ip Number : " + mySqlReader("c_ipnumber") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "PowerSupply : " + mySqlReader("c_ps") + "CD/DVD : " + mySqlReader("c_cd") + "Case : " + mySqlReader("c_case") + "IpAddress : " + mySqlReader("c_ipnumber") + "Computername : " + mySqlReader("c_comname") + " Windows : " + mySqlReader("c_windows") + "Office : " + mySqlReader("c_office") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Size : " + mySqlReader("m_size") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Type : " + mySqlReader("p_type") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.Add("Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price") + "Amount : " + mySqlReader("amount"))
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.Add("Serial Number : " + mySqlReader("serialnumber") + "IP Address : " + mySqlReader("c_ipnumber") + "Pass-Connect : " + mySqlReader("pass_connect") + "Pass-Config : " + mySqlReader("pass_config") + "Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("state_device") IsNot DBNull.Value Then
                        .SubItems.Add(mySqlReader("state_device"))
                    End If

                End With
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()
    End Sub

    ''โค้ดปุ่ม search e.KeyCode = "13" = กด enter แสดงข้อมูล

    Private Sub txtsearchcom_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtsearchcom.KeyDown
        If e.KeyCode = "13" Then
            showdatacom1()
        End If
    End Sub

    Private Sub txtsearchprin_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtsearchprin.KeyDown
        If e.KeyCode = "13" Then
            showdataprinter2()
        End If
    End Sub

    Private Sub txtsearchmonitor_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtsearchmonitor.KeyDown
        If e.KeyCode = "13" Then
            showdatamonitor3()
        End If
    End Sub

    Private Sub txtsearchother_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtsearchother.KeyDown
        If e.KeyCode = "13" Then
            showdataother4()
        End If
    End Sub

    Private Sub txtsearchlicense_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtsearchlicense.KeyDown
        If e.KeyCode = "13" Then
            showdatalicense5()
        End If
    End Sub

    Private Sub txtsearchnet_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtsearchnet.KeyDown
        If e.KeyCode = "13" Then
            showdatanetwork6()
        End If
    End Sub


    ''โค้ดแสดงข้อมูลในตาราง 6/6/56 ***********************************************************

    ''Computer
    Private Sub ListViewcom_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewcom.Click
        idkey = ListViewcom.SelectedItems(0).SubItems(0).Text

        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If

        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader


        mySqlCommand.CommandText = "SELECT * FROM data_device where iddata_device = '" & idkey & "' ;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader



            While (mySqlReader.Read())

                tab3brand.Text = mySqlReader("name")
                tab3model.Text = mySqlReader("model")
                tab3cpu.Text = mySqlReader("c_cpu")
                tab3mb.Text = mySqlReader("c_mainboard")
                tab3ram.Text = mySqlReader("c_ram")
                tab3hd.Text = mySqlReader("c_harddisk")
                tab3vga.Text = mySqlReader("c_vgacard")
                tab3ipnumber.Text = mySqlReader("c_ipnumber")
                tab3detail.Text = mySqlReader("detail")
                tab3ps.Text = mySqlReader("c_ps")
                tab3cd.Text = mySqlReader("c_cd")
                tab3case.Text = mySqlReader("c_case")
                tab3serial.Text = mySqlReader("serialnumber")
                tab3comname.Text = mySqlReader("c_comname")
                tab3windows.Text = mySqlReader("c_windows")
                tab3office.Text = mySqlReader("c_office")
                tab3other.Text = mySqlReader("c_other")
                tab3id.Text = mySqlReader("iddata_device")
                tab3price.Text = mySqlReader("price")
                If mySqlReader("computerhims") = "มี" Then
                    CheckBoxhims.Checked = True
                Else
                    CheckBoxhims.Checked = False
                End If
                If mySqlReader("computerpacs") = "มี" Then
                    CheckBoxpacs.Checked = True
                Else
                    CheckBoxpacs.Checked = False
                End If
                If mySqlReader("computerlab") = "มี" Then
                    CheckBoxlab.Checked = True
                Else
                    CheckBoxlab.Checked = False
                End If
                If mySqlReader("computersystem") = "มี" Then
                    CheckBoxsystem.Checked = True
                Else
                    CheckBoxsystem.Checked = False
                End If
                If mySqlReader("computeradmin") = "มี" Then
                    CheckBoxadmin.Checked = True
                Else
                    CheckBoxadmin.Checked = False
                End If
                If mySqlReader("computerdeep") = "มี" Then
                    CheckBoxdeep.Checked = True
                Else
                    CheckBoxdeep.Checked = False
                End If

            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()

        ''5/6/56 ***************************************************************

    End Sub

    ''Printer
    Private Sub ListViewprin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewprin.Click
        idkey = ListViewprin.SelectedItems(0).SubItems(0).Text
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader

        mySqlCommand.CommandText = "SELECT * FROM data_device where iddata_device = '" & idkey & "' ;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand
        Try
            mySqlReader = mySqlCommand.ExecuteReader
            While (mySqlReader.Read())
                tab2brand.Text = mySqlReader("name")
                tab2model.Text = mySqlReader("model")
                tab2id.Text = mySqlReader("iddata_device")
                tab2detail.Text = mySqlReader("detail")
                tab2serial.Text = mySqlReader("serialnumber")
                tab2price.Text = mySqlReader("price")
                If mySqlReader("p_type") = "Laser Printer สี" Then
                    Radiolaserc.Checked = True
                Else
                    Radiolaserc.Checked = False
                End If
                If mySqlReader("p_type") = "Laser Printer ขาว-ดำ" Then
                    Radiolaserwb.Checked = True
                Else
                    Radiolaserwb.Checked = False
                End If
                If mySqlReader("p_type") = "Dot-matrix Printer" Then
                    Radiodot.Checked = True
                Else
                    Radiodot.Checked = False
                End If
                If mySqlReader("p_type") = "Inkjet Printer" Then
                    Radioinkjet.Checked = True
                Else
                    Radioinkjet.Checked = False
                End If
                If mySqlReader("p_type") = "Sticker Printer" Then
                    Radiosticker.Checked = True
                Else
                    Radiosticker.Checked = False
                End If
                If mySqlReader("p_type") = "Inkjet-all in one" Then
                    Radioinkall.Checked = True
                Else
                    Radioinkall.Checked = False
                End If
                If mySqlReader("p_type") = "Laser-all in one" Then
                    Radiolaserall.Checked = True
                Else
                    Radiolaserall.Checked = False
                End If
                If mySqlReader("p_type") = "Laser-multifunction" Then
                    Radiolasermulti.Checked = True
                Else
                    Radiolasermulti.Checked = False
                End If

            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()

        ''6/6/56 *******************************************************************
    End Sub

    ''Monitor
    Private Sub ListViewmonitor_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewmonitor.Click
        idkey = ListViewmonitor.SelectedItems(0).SubItems(0).Text
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader

        mySqlCommand.CommandText = "SELECT * FROM data_device where iddata_device = '" & idkey & "' ;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand
        Try
            mySqlReader = mySqlCommand.ExecuteReader
            While (mySqlReader.Read())
                tab1brand.Text = mySqlReader("name")
                tab1model.Text = mySqlReader("model")
                tab1id.Text = mySqlReader("iddata_device")
                tab1detail.Text = mySqlReader("detail")
                tab1serial.Text = mySqlReader("serialnumber")
                tab1size.Text = mySqlReader("m_size")
                tab1price.Text = mySqlReader("price")

            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()
        ''6/6/56 ****************************************************************

    End Sub

    ''Other


    Private Sub ListViewother_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewother.Click
        idkey = ListViewother.SelectedItems(0).SubItems(0).Text
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader

        mySqlCommand.CommandText = "SELECT * FROM data_device where iddata_device = '" & idkey & "' ;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand
        Try
            mySqlReader = mySqlCommand.ExecuteReader
            While (mySqlReader.Read())
                tab4brand.Text = mySqlReader("name")
                tab4model.Text = mySqlReader("model")
                tab4id.Text = mySqlReader("iddata_device")
                tab4detail.Text = mySqlReader("detail")
                tab4serial.Text = mySqlReader("serialnumber")
                tab4price.Text = mySqlReader("price")
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()

        ''6/6/56 ***************************************************************
    End Sub

    ''license 12/6/56
    Private Sub ListViewlicense_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewlicense.Click
        idkey = ListViewlicense.SelectedItems(0).SubItems(0).Text
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader

        mySqlCommand.CommandText = "SELECT * FROM data_device where iddata_device = '" & idkey & "' ;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand
        Try
            mySqlReader = mySqlCommand.ExecuteReader
            While (mySqlReader.Read())
                tab5brand.Text = mySqlReader("name")
                tab5detail.Text = mySqlReader("detail")
                tab5id.Text = mySqlReader("iddata_device")
                tab5amount.Text = mySqlReader("amount")
                tab5price.Text = mySqlReader("price")
                If mySqlReader("windows_application") = "OS" Then
                    Radioos.Checked = True
                Else
                    Radioos.Checked = False
                End If
                If mySqlReader("windows_application") = "Application" Then
                    Radioapp.Checked = True
                Else
                    Radioapp.Checked = False
                End If
                ''โค้ดปุ่มเลือกเวลา
                Dim date_as As Date
                date_as = "#" + mySqlReader("startbuy") + "#"
                DateTimePicker1.Value = date_as

                date_as = "#" + mySqlReader("warrant") + "#"
                DateTimePicker2.Value = date_as


            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()
    End Sub

    ''Network 12/6/56
    Private Sub ListViewnet_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewnet.Click
        idkey = ListViewnet.SelectedItems(0).SubItems(0).Text
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader

        mySqlCommand.CommandText = "SELECT * FROM data_device where iddata_device = '" & idkey & "' ;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand
        Try
            mySqlReader = mySqlCommand.ExecuteReader
            While (mySqlReader.Read())
                tab6brand.Text = mySqlReader("name")
                tab6ipnumber.Text = mySqlReader("c_ipnumber")
                tab6id.Text = mySqlReader("iddata_device")
                tab6detail.Text = mySqlReader("detail")
                tab6serial.Text = mySqlReader("serialnumber")
                tab6price.Text = mySqlReader("price")
                tab6passconnect.Text = mySqlReader("pass_connect")
                tab6passconfig.Text = mySqlReader("pass_config")
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()
    End Sub


    '' โค้ดแก้ไขข้อมูลในปุ่ม save แต่ละหน้า 7/6/56**************************************************

    ''computer
    Private Sub btnsavecom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsavecom.Click
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim size As String
        Dim condition As String
        Dim respone As Object
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        Dim computerhims As String
        Dim computerpacs As String
        Dim computerlab As String
        Dim computersystem As String
        Dim computeradmin As String
        Dim computerdeep As String
        If CheckBoxhims.Checked = True Then
            computerhims = "มี"
        ElseIf CheckBoxhims.Checked = False Then
            computerhims = "ไม่มี"
        End If
        If CheckBoxpacs.Checked = True Then
            computerpacs = "มี"
        ElseIf CheckBoxpacs.Checked = False Then
            computerpacs = "ไม่มี"
        End If
        If CheckBoxlab.Checked = True Then
            computerlab = "มี"
        ElseIf CheckBoxlab.Checked = False Then
            computerlab = "ไม่มี"
        End If
        If CheckBoxsystem.Checked = True Then
            computersystem = "มี"
        ElseIf CheckBoxsystem.Checked = False Then
            computersystem = "ไม่มี"
        End If
        If CheckBoxadmin.Checked = True Then
            computeradmin = "มี"
        ElseIf CheckBoxadmin.Checked = False Then
            computeradmin = "ไม่มี"
        End If
        If CheckBoxdeep.Checked = True Then
            computerdeep = "มี"
        ElseIf CheckBoxdeep.Checked = False Then
            computerdeep = "ไม่มี"
        End If
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        Dim commandText2 As String
        respone = MsgBox("ยืนยันข้อมูลถูกต้อง by โตน ลูกพี่อารี", MsgBoxStyle.OkCancel + MsgBoxStyle.Information, "Warning Messsage")

        If respone = 1 Then
            Try
                commandText2 = "UPDATE data_device SET name = '" & tab3brand.Text & "' , model = '" & tab3model.Text & "' , c_cpu = '" & tab3cpu.Text & "' , c_mainboard = '" & tab3mb.Text & "', c_ram = '" & tab3ram.Text & "' ,c_harddisk = '" & tab3hd.Text & "' ,c_vgacard = '" & tab3vga.Text & "',c_ipnumber = '" & tab3ipnumber.Text & "',detail = '" & tab3detail.Text & "',c_ps = '" & tab3ps.Text & "' ,c_cd = '" & tab3cd.Text & "',c_case = '" & tab3case.Text & "',serialnumber = '" & tab3serial.Text & "',price = '" & tab3price.Text & "',c_comname = '" & tab3comname.Text & "',c_windows = '" & tab3windows.Text & "',c_office = '" & tab3office.Text & "',c_other = '" & tab3other.Text & "',state_device = ' ว่าง ',computerhims = '" & computerhims & "',computerpacs = '" & computerpacs & "',computerlab = '" & computerlab & "',computersystem = '" & computersystem & "',computeradmin = '" & computeradmin & "',computerdeep = '" & computerdeep & "' WHERE iddata_device = " & tab3id.Text & "; "
                mySqlCommand.CommandText = commandText2
                mySqlCommand.CommandType = CommandType.Text
                mySqlCommand.Connection = sql
                mySqlCommand.ExecuteNonQuery()


            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try

        End If
        showdatacom1()
        tab3id.Text = ""
        tab3brand.Text = ""
        tab3model.Text = ""
        tab3cd.Text = ""
        tab3cpu.Text = ""
        tab3hd.Text = ""
        tab3mb.Text = ""
        tab3vga.Text = ""
        tab3ram.Text = ""
        tab3ipnumber.Text = ""
        tab3serial.Text = ""
        tab3detail.Text = ""
        tab3ps.Text = ""
        tab3case.Text = ""
        tab3comname.Text = ""
        tab3windows.Text = ""
        tab3office.Text = ""
        tab3other.Text = ""
        tab3price.Text = ""
        CheckBoxhims.Checked = False
        CheckBoxpacs.Checked = False
        CheckBoxlab.Checked = False
        CheckBoxsystem.Checked = False
        CheckBoxadmin.Checked = False
        CheckBoxdeep.Checked = False

    End Sub

    ''printer
    Private Sub btnsaveprin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsaveprin.Click
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim size As String
        Dim condition As String
        Dim respone As Object
        Dim printer As String
        If Radiolaserc.Checked = True Then
            printer = "Laser Printer สี"
        End If
        If Radiolaserwb.Checked = True Then
            printer = "Laser Printer ขาว-ดำ"
        End If
        If Radiodot.Checked = True Then
            printer = "Dot-matrix Printer"
        End If
        If Radioinkjet.Checked = True Then
            printer = "Inkjet Printer"
        End If
        If Radiosticker.Checked = True Then
            printer = "Sticker Printer"
        End If
        If Radioinkall.Checked = True Then
            printer = "Inkjet-all in one"
        End If
        If Radiolaserall.Checked = True Then
            printer = "Laser-all in one"
        End If
        If Radiolasermulti.Checked = True Then
            printer = "Laser-multifunction"
        End If
        Dim commandText2 As String
        respone = MsgBox("ยืนยันข้อมูลถูกต้อง by โตน ลูกพี่อารี", MsgBoxStyle.OkCancel + MsgBoxStyle.Information, "Warning Messsage")
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        If respone = 1 Then


            Try
                commandText2 = "UPDATE data_device SET name = '" & tab2brand.Text & "' , model = '" & tab2model.Text & "' , serialnumber = '" & tab2serial.Text & "', detail = '" & tab2detail.Text & "', p_type = '" & printer & "', price = '" & tab2price.Text & "' WHERE iddata_device = " & tab2id.Text & "; "
                mySqlCommand.CommandText = commandText2
                mySqlCommand.CommandType = CommandType.Text
                mySqlCommand.Connection = sql
                mySqlCommand.ExecuteNonQuery()
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End If
        showdataprinter2()
        tab2brand.Text = ""
        tab2model.Text = ""
        tab2detail.Text = ""
        tab2serial.Text = ""
        tab2price.Text = ""
        Radiolaserc.Checked = False
        Radiolaserwb.Checked = False
        Radiodot.Checked = False
        Radioinkjet.Checked = False
        Radiosticker.Checked = False
        Radioinkall.Checked = False
        Radiolaserall.Checked = False
        Radiolasermulti.Checked = False

    End Sub

    ''Monitor
    Private Sub btnsavemonitor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsavemonitor.Click
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim size As String
        Dim condition As String
        Dim respone As Object
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If

        Dim commandText2 As String
        respone = MsgBox("ยืนยันข้อมูลถูกต้อง by โตน ลูกพี่อารี", MsgBoxStyle.OkCancel + MsgBoxStyle.Information, "Warning Messsage")

        If respone = 1 Then


            Try
                commandText2 = "UPDATE data_device SET name = '" & tab1brand.Text & "' , model = '" & tab1model.Text & "' , serialnumber = '" & tab1serial.Text & "', detail = '" & tab1detail.Text & "', m_size = '" & tab1size.Text & "' WHERE iddata_device = " & tab1id.Text & "; "

                mySqlCommand.CommandText = commandText2
                mySqlCommand.CommandType = CommandType.Text
                mySqlCommand.Connection = sql

                mySqlCommand.ExecuteNonQuery()


            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try

        End If
        showdatamonitor3()
        tab1model.Text = ""
        tab1brand.Text = ""
        tab1size.Text = ""
        tab1detail.Text = ""
        tab1serial.Text = ""
        tab1price.Text = ""
    End Sub

    ''Other
    Private Sub btnsaveother_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsaveother.Click
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim size As String
        Dim condition As String
        Dim respone As Object
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If

        Dim commandText2 As String
        respone = MsgBox("ยืนยันข้อมูลถูกต้อง by โตน ลูกพี่อารี", MsgBoxStyle.OkCancel + MsgBoxStyle.Information, "Warning Messsage")

        If respone = 1 Then
            Try
                commandText2 = "UPDATE data_device SET name = '" & tab4brand.Text & "' , model = '" & tab4model.Text & "' , serialnumber = '" & tab4serial.Text & "', detail = '" & tab4detail.Text & "'  WHERE iddata_device = " & tab4id.Text & "; "

                mySqlCommand.CommandText = commandText2
                mySqlCommand.CommandType = CommandType.Text
                mySqlCommand.Connection = sql
                mySqlCommand.ExecuteNonQuery()


            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End If
        showdataother4()
        tab4brand.Text = ""
        tab4model.Text = ""
        tab4detail.Text = ""
        tab4serial.Text = ""
        tab4price.Text = ""
    End Sub

    ''license 12/6/56
    Private Sub btnsavelicense_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsavelicense.Click
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim size As String
        Dim condition As String
        Dim respone As Object
        Dim windows_application As String
        If Radioos.Checked = True Then
            windows_application = "OS"
        End If
        If Radioapp.Checked = True Then
            windows_application = "Application"
        End If

        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If

        Dim commandText2 As String
        respone = MsgBox("ยืนยันข้อมูลถูกต้อง by โตน ลูกพี่อารี", MsgBoxStyle.OkCancel + MsgBoxStyle.Information, "Warning Messsage")

        If respone = 1 Then

            Try
                commandText2 = "UPDATE data_device SET name = '" & tab5brand.Text & "' , amount = '" & tab5amount.Text & "' , price = '" & tab5price.Text & "', detail = '" & tab5detail.Text & "',windows_application = '" & windows_application & "' WHERE iddata_device = " & tab5id.Text & ";"
                mySqlCommand.CommandText = commandText2
                mySqlCommand.CommandType = CommandType.Text
                mySqlCommand.Connection = sql
                mySqlCommand.ExecuteNonQuery()
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End If

        showdatalicense5()
        tab5brand.Text = ""
        tab5amount.Text = ""
        tab5detail.Text = ""
        tab5price.Text = ""
        Radioos.Checked = False
        Radioapp.Checked = False
    End Sub

    ''Network 12/6/56
    Private Sub btnsavenet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsavenet.Click
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim size As String
        Dim condition As String
        Dim respone As Object
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If

        Dim commandText2 As String
        respone = MsgBox("ยืนยันข้อมูลถูกต้อง by โตน ลูกพี่อารี", MsgBoxStyle.OkCancel + MsgBoxStyle.Information, "Warning Messsage")

        If respone = 1 Then
            Try
                commandText2 = "UPDATE data_device SET name = '" & tab6brand.Text & "' , serialnumber = '" & tab6serial.Text & "' , c_ipnumber = '" & tab6ipnumber.Text & "', pass_connect = '" & tab6passconnect.Text & "', pass_config = '" & tab6passconfig.Text & "', detail = '" & tab6detail.Text & "', price = '" & tab6price.Text & "'  WHERE iddata_device = " & tab6id.Text & "; "

                mySqlCommand.CommandText = commandText2
                mySqlCommand.CommandType = CommandType.Text
                mySqlCommand.Connection = sql

                mySqlCommand.ExecuteNonQuery()


            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End If

        showdatanetwork6()
        tab6brand.Text = ""
        tab6detail.Text = ""
        tab6serial.Text = ""
        tab6ipnumber.Text = ""
        tab6passconnect.Text = ""
        tab6passconfig.Text = ""
        tab6price.Text = ""
    End Sub

    ''โค้ดลบข้อมูลในปุ่ม *************************************** 7/6/56**************************

    ''other
    Private Sub btndeleteother_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndeleteother.Click
        If tab4id.Text <> "" Then

            DeleteData4()
        Else
            MsgBox("กรุณาเลือกข้อมูลในตารางที่จะลบออกนะจ๊ะ By โตน ลูกพี่อารี")
        End If
        showdataother4()
        tab4brand.Text = ""
        tab4model.Text = ""
        tab4detail.Text = ""
        tab4serial.Text = ""
        tab4price.Text = ""
    End Sub
    Private Sub DeleteData4()

        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim respone As Object
        respone = MsgBox("ต้องการลบข้อมูลนี้หรือไม่จ๊ะ  By โตน ลูกพี่อารี ", MsgBoxStyle.OkCancel + MsgBoxStyle.Information, "Warning Messsage")
        If respone = 1 Then
            If tab4id.Text <> "" Then

                If sql.State = ConnectionState.Closed Then
                    sql.Open()
                End If
                Try

                    mySqlCommand.CommandText = "DELETE FROM data_device where iddata_device = '" & tab4id.Text & "';"
                    mySqlCommand.CommandType = CommandType.Text
                    mySqlCommand.Connection = sql

                    mySqlCommand.ExecuteNonQuery()
                    sql.Close()
                Catch ex As Exception

                    MsgBox(ex.ToString)
                    Exit Sub
                End Try

                If sql.State = ConnectionState.Closed Then
                    sql.Open()
                End If


            End If
        End If

    End Sub

    ''computer
    Private Sub btndeletecom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndeletecom.Click
        If tab3id.Text <> "" Then

            DeleteData1()
        Else
            MsgBox("กรุณาเลือกข้อมูลในตารางที่จะลบออกนะจ๊ะ By โตน ลูกพี่อารี")
        End If
        showdatacom1()
        tab3id.Text = ""
        tab3brand.Text = ""
        tab3model.Text = ""
        tab3cd.Text = ""
        tab3cpu.Text = ""
        tab3hd.Text = ""
        tab3mb.Text = ""
        tab3vga.Text = ""
        tab3ram.Text = ""
        tab3ipnumber.Text = ""
        tab3serial.Text = ""
        tab3detail.Text = ""
        tab3ps.Text = ""
        tab3case.Text = ""
        tab3comname.Text = ""
        tab3windows.Text = ""
        tab3office.Text = ""
        tab3other.Text = ""
        tab3price.Text = ""
        CheckBoxhims.Checked = False
        CheckBoxpacs.Checked = False
        CheckBoxlab.Checked = False
        CheckBoxsystem.Checked = False
        CheckBoxadmin.Checked = False
        CheckBoxdeep.Checked = False
    End Sub
    Private Sub DeleteData1()

        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim respone As Object
        respone = MsgBox("ต้องการลบข้อมูลนี้หรือไม่จ๊ะ  By โตน ลูกพี่อารี ", MsgBoxStyle.OkCancel + MsgBoxStyle.Information, "Warning Messsage")
        If respone = 1 Then
            If tab3id.Text <> "" Then

                If sql.State = ConnectionState.Closed Then
                    sql.Open()
                End If
                Try

                    mySqlCommand.CommandText = "DELETE FROM data_device where iddata_device = '" & tab3id.Text & "';"
                    mySqlCommand.CommandType = CommandType.Text
                    mySqlCommand.Connection = sql

                    mySqlCommand.ExecuteNonQuery()
                    sql.Close()
                Catch ex As Exception

                    MsgBox(ex.ToString)
                    Exit Sub
                End Try

                If sql.State = ConnectionState.Closed Then
                    sql.Open()
                End If


            End If
        End If

    End Sub

    ''printer
    Private Sub btndeleteprin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndeleteprin.Click
        If tab2id.Text <> "" Then

            DeleteData2()
        Else
            MsgBox("กรุณาเลือกข้อมูลในตารางที่จะลบออกนะจ๊ะ By โตน ลูกพี่อารี")
        End If
        showdataprinter2()
        tab2brand.Text = ""
        tab2model.Text = ""
        tab2detail.Text = ""
        tab2serial.Text = ""
        tab2price.Text = ""
        Radiolaserc.Checked = False
        Radiolaserwb.Checked = False
        Radiodot.Checked = False
        Radioinkjet.Checked = False
        Radiosticker.Checked = False
        Radioinkall.Checked = False
        Radiolaserall.Checked = False
        Radiolasermulti.Checked = False
    End Sub
    Private Sub DeleteData2()

        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim respone As Object
        respone = MsgBox("ต้องการลบข้อมูลนี้หรือไม่จ๊ะ  By โตน ลูกพี่อารี ", MsgBoxStyle.OkCancel + MsgBoxStyle.Information, "Warning Messsage")
        If respone = 1 Then
            If tab2id.Text <> "" Then

                If sql.State = ConnectionState.Closed Then
                    sql.Open()
                End If
                Try

                    mySqlCommand.CommandText = "DELETE FROM data_device where iddata_device = '" & tab2id.Text & "';"
                    mySqlCommand.CommandType = CommandType.Text
                    mySqlCommand.Connection = sql

                    mySqlCommand.ExecuteNonQuery()
                    sql.Close()
                Catch ex As Exception

                    MsgBox(ex.ToString)
                    Exit Sub
                End Try

                If sql.State = ConnectionState.Closed Then
                    sql.Open()
                End If


            End If
        End If

    End Sub

    ''monitor
    Private Sub btndeletemonitor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndeletemonitor.Click
        If tab1id.Text <> "" Then

            DeleteData3()
        Else
            MsgBox("กรุณาเลือกข้อมูลในตารางที่จะลบออกนะจ๊ะ By โตน ลูกพี่อารี")
        End If
        showdatamonitor3()
        tab1model.Text = ""
        tab1brand.Text = ""
        tab1size.Text = ""
        tab1detail.Text = ""
        tab1serial.Text = ""
        tab1price.Text = ""
    End Sub
    Private Sub DeleteData3()

        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim respone As Object
        respone = MsgBox("ต้องการลบข้อมูลนี้หรือไม่จ๊ะ  By โตน ลูกพี่อารี ", MsgBoxStyle.OkCancel + MsgBoxStyle.Information, "Warning Messsage")
        If respone = 1 Then
            If tab1id.Text <> "" Then

                If sql.State = ConnectionState.Closed Then
                    sql.Open()
                End If
                Try

                    mySqlCommand.CommandText = "DELETE FROM data_device where iddata_device = '" & tab1id.Text & "';"
                    mySqlCommand.CommandType = CommandType.Text
                    mySqlCommand.Connection = sql

                    mySqlCommand.ExecuteNonQuery()
                    sql.Close()
                Catch ex As Exception

                    MsgBox(ex.ToString)
                    Exit Sub
                End Try

                If sql.State = ConnectionState.Closed Then
                    sql.Open()
                End If


            End If
        End If

    End Sub

    ''license 12/6/56
    Private Sub btndeletelicense_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndeletelicense.Click
        If tab5id.Text <> "" Then

            DeleteData5()
        Else
            MsgBox("กรุณาเลือกข้อมูลในตารางที่จะลบออกนะจ๊ะ By โตน ลูกพี่อารี")
        End If
        showdatalicense5()
        tab5brand.Text = ""
        tab5amount.Text = ""
        tab5detail.Text = ""
        tab5price.Text = ""
        Radioos.Checked = False
        Radioapp.Checked = False
    End Sub
    Private Sub DeleteData5()

        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim respone As Object
        respone = MsgBox("ต้องการลบข้อมูลนี้หรือไม่จ๊ะ  By โตน ลูกพี่อารี ", MsgBoxStyle.OkCancel + MsgBoxStyle.Information, "Warning Messsage")
        If respone = 1 Then
            If tab5id.Text <> "" Then

                If sql.State = ConnectionState.Closed Then
                    sql.Open()
                End If
                Try

                    mySqlCommand.CommandText = "DELETE FROM data_device where iddata_device = '" & tab5id.Text & "';"
                    mySqlCommand.CommandType = CommandType.Text
                    mySqlCommand.Connection = sql

                    mySqlCommand.ExecuteNonQuery()
                    sql.Close()
                Catch ex As Exception

                    MsgBox(ex.ToString)
                    Exit Sub
                End Try

                If sql.State = ConnectionState.Closed Then
                    sql.Open()
                End If


            End If
        End If

    End Sub

    ''Network 12/6/56
    Private Sub btndeletenet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndeletenet.Click
        If tab6id.Text <> "" Then

            DeleteData6()
        Else
            MsgBox("กรุณาเลือกข้อมูลในตารางที่จะลบออกนะจ๊ะ By โตน ลูกพี่อารี")
        End If

        showdatanetwork6()
        tab6brand.Text = ""
        tab6detail.Text = ""
        tab6serial.Text = ""
        tab6ipnumber.Text = ""
        tab6passconnect.Text = ""
        tab6passconfig.Text = ""
        tab6price.Text = ""
    End Sub
    Private Sub DeleteData6()

        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim respone As Object
        respone = MsgBox("ต้องการลบข้อมูลนี้หรือไม่จ๊ะ  By โตน ลูกพี่อารี ", MsgBoxStyle.OkCancel + MsgBoxStyle.Information, "Warning Messsage")
        If respone = 1 Then
            If tab6id.Text <> "" Then

                If sql.State = ConnectionState.Closed Then
                    sql.Open()
                End If
                Try

                    mySqlCommand.CommandText = "DELETE FROM data_device where iddata_device = '" & tab6id.Text & "';"
                    mySqlCommand.CommandType = CommandType.Text
                    mySqlCommand.Connection = sql

                    mySqlCommand.ExecuteNonQuery()
                    sql.Close()
                Catch ex As Exception

                    MsgBox(ex.ToString)
                    Exit Sub
                End Try

                If sql.State = ConnectionState.Closed Then
                    sql.Open()
                End If


            End If
        End If

    End Sub

    '' โค้ดปุ่มsearch คลิกแล้วโชว์ข้อมูล 11/6/56 ****************************************************

    Private Sub btnsearchcom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearchcom.Click
        showdatacom1()
    End Sub

    Private Sub btnsearchprin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearchprin.Click
        showdataprinter2()
    End Sub

    Private Sub btnsearchmonitor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearchmonitor.Click
        showdatamonitor3()
    End Sub

    Private Sub btnsearchother_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearchother.Click
        showdataother4()
    End Sub

    Private Sub btnsearchlicense_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearchlicense.Click
        showdatalicense5()
    End Sub

    Private Sub btnsearchnet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearchnet.Click
        showdatanetwork6()
    End Sub

    ''โค้ดเมนู 15/6/56 ************************************************************************

    Private Sub เพมขอมลอปกรณToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles เพมขอมลอปกรณToolStripMenuItem.Click
        Dim NextForm As add = New add(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        Me.Hide()
        NextForm.ShowDialog()
    End Sub

    'Private Sub แสดงขอมลอปกรณToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles แสดงขอมลอปกรณToolStripMenuItem.Click
    'Dim NextForm As Editdevice = New Editdevice(mysqlpass, ipconnect, usernamedb, dbname)
    '  Dim NextForm As main_user = New main_user()
    '  NextForm.Show()
    '   Me.Hide()
    ' End Sub

    Private Sub เพมแผนกToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles เพมแผนกToolStripMenuItem.Click
        Dim NextForm As Adddepartment = New Adddepartment(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub จองอปกรณToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles จองอปกรณToolStripMenuItem.Click
        Dim NextForm As device_department = New device_department(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub จองอปกรณกลมToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles จองอปกรณกลมToolStripMenuItem.Click
        Dim NextForm As add_department_group = New add_department_group(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub แกไขแผนกToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles แกไขแผนกToolStripMenuItem.Click
        Dim NextForm As add_department_group = New add_department_group(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub บนทกประวตบำรงรกษาToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles บนทกประวตบำรงรกษาToolStripMenuItem.Click
        Dim NextForm As historydetail = New historydetail(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub บำรงรกษาToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles บำรงรกษาToolStripMenuItem.Click
        Dim NextForm As addhistory = New addhistory(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub
End Class